package com.ly.hotel.spainterface.jg.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.ly.hotel.R;
import com.ly.hotel.spainterface.jg.ActivityCollector;

/**
 * Created by ThinkPad on 2018/1/31.
 */

public class CustomErrorDialog {

    public Dialog mErrorDialog;
    private Window window = null;

    public CustomErrorDialog(final Context context, final String errorMsg){

        mErrorDialog = new Dialog(context, R.style.ActionSheetDialogStyle);
        View errorLayout = LayoutInflater.from(context).inflate(R.layout.jg_custom_error_dialog,null);
        Button errorConfirm = (Button) errorLayout.findViewById(R.id.error_confirm);
        TextView errorTips = (TextView) errorLayout.findViewById(R.id.error_tips);
        ImageButton errorTipsClose = (ImageButton) errorLayout.findViewById(R.id.error_tips_close);
        mErrorDialog.setContentView(errorLayout);//设置自定义Dialog布局
        Window dialogWindow = mErrorDialog.getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        /*WindowManager.LayoutParams params = dialogWindow.getAttributes();
        params.y = 20;// 距离底部的距离
        dialogWindow.setAttributes(params);*/
        mErrorDialog.setCancelable(false);// 设置不可点空白区域取消Dialog
        errorTips.setText(errorMsg);

        errorConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityCollector.finishAll();
            }
        });

        errorTipsClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
            }
        });

    }

    public void show(){
        mErrorDialog.show();
    }

    public void close(){
        if(mErrorDialog != null){
            mErrorDialog.dismiss();
            mErrorDialog = null;
        }
    }

}
